cmake_minimum_required(VERSION 3.5.1)

# 启用策略 CMP0071，允许处理 GENERATED 文件
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.10)
    cmake_policy(SET CMP0071 NEW)
endif ()

project(qt_-test)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/")
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.9.1/5.9.1/mingw53_32")
#set(CMAKE_PREFIX_PATH "D:/c++/Qt/Qt5.9.1/5.9.1/mingw53_32")


find_package(Qt5 COMPONENTS
        Core
        Gui
        Widgets
        Network
        Sql
        REQUIRED)

# 旧版本资源配置方式
set(RCC_RESOURCES
        config/resources.qrc
)

# 生成资源文件（Qt5.11之前）
QT5_ADD_RESOURCES(RCC_SRCS ${RCC_RESOURCES})

add_executable(qt_-test main.cpp
        mainwindow.h
        mainwindow.cpp
        ${RCC_SRCS}  # 包含生成的资源文件
        satellitehandler.h
        satellitehandler.cpp
        config/configtablewidget.cpp
        config/configtablewidget.h
        window.cpp
        window.h
        widgets/TopWidget.cpp
        widgets/TopWidget.h
        command/ICommand.h
        command/TestCommand.h
        widgets/BottomWidget.cpp
        widgets/BottomWidget.h
        widgets/bottomWidgetContent/LeftWidget.cpp
        widgets/bottomWidgetContent/LeftWidget.h
        widgets/bottomWidgetContent/RightWidget.cpp
        widgets/bottomWidgetContent/RightWidget.h
        command/NewWindowRightWidgetCommand.h
        widgets/RightWidgetWindow.h
        SatelliteContentFactory/SatelliteContent.h
        SatelliteContentFactory/BDSatelliteContent.h
        SatelliteContentFactory/GPSSatelliteContent.h
        SatelliteContentFactory/GalileoSatelliteContent.h
        SatelliteContentFactory/SatelliteContentFactory.h
        widgets/bottomWidgetContent/LeftWidget.cpp
        widgets/bottomWidgetContent/QComboBoxManager.h
        widgets/bottomWidgetContent/MyWidget.h
        widgets/bottomWidgetContent/TableWidget.h
)
target_link_libraries(qt_-test
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
        Qt5::Network
        Qt5::Sql
)

if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
    set(DEBUG_SUFFIX)
    if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
        set(DEBUG_SUFFIX "d")
    endif ()
    set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
    if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
        set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
            set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        endif ()
    endif ()
    if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E make_directory
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
    endif ()
    foreach (QT_LIB Core Gui Widgets)
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>")
    endforeach (QT_LIB)
endif ()